/**
 * 
 */
package com.fandy.struts.SqlAccess;
 import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

//import com.microsoft.sqlserver.jdbc.*;
// import com.microsoft.*;
//import com.microsoft.sqlserver.*;

/**
 * @author Administrator
 *
 */
public class SqlHelper {

	// Declare the JDBC objects.	
private  Connection con = null;
private	 Statement stmt = null;
private  ResultSet rs = null;

public static String connectionUrl = "jdbc:sqlserver://localhost:1433;" +
	"databaseName=AdventureWorks;integratedSecurity=true;" ;


public SqlHelper()
{

	try {
		// Establish the connection.
		Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
    		con = DriverManager.getConnection(connectionUrl);
    
    		// Create and execute an SQL statement that returns some data.
//    		String SQL = "SELECT TOP 10 * FROM Person.Contact";
//    		stmt = con.createStatement();
//    		rs = stmt.executeQuery(SQL);
//    
//    		// Iterate through the data in the result set and display it.
//    		while (rs.next()) {
//    			System.out.println(rs.getString(4) + " " + rs.getString(6));
//    		}   		
    		
	     }

// Handle any errors that may have occurred.
	catch (Exception e) {
		e.printStackTrace();
	}

	finally {
		if (rs != null) try { rs.close(); } catch(Exception e) {}
			if (stmt != null) try { stmt.close(); } catch(Exception e) {}
			if (con != null) try { con.close(); } catch(Exception e) {}
			}
	}

}
	

